package com.kjzy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kjzy.mapper.TimeMapper;
import com.kjzy.pojo.Appoint;
import com.kjzy.pojo.Reservation;
import com.kjzy.service.TimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TimeServiceImpl implements TimeService {

    @Autowired
    private TimeMapper timeMapper;
    public PageInfo<Appoint> findAllTime(Appoint appoint,int pageNum, int pageSize) {
        //pageNum:当前页   pageSize：每页条数
        PageHelper.startPage(pageNum,pageSize);
        // 调用MyBatis的Mapper方法进行查询
        List<Appoint> timeList=timeMapper.findAllTime(appoint);
        // 返回分页信息
        return new PageInfo<Appoint>(timeList);
    }

    public String insertT(Appoint appoint) {
        int rows = this.timeMapper.insertT(appoint);
        // 2-2.判断更新用户是否成功。如果更新用户成功，
        // 则返回"SUCCESS"，否则返回失败信息。
        if (rows > 0) {
            return "SUCCESS";
        } else {
            return "update user failure.";
        }
    }

    public String updateT(Appoint appoint) {
        int rows = this.timeMapper.updateT(appoint);
        // 2-2.判断更新用户是否成功。如果更新用户成功，
        // 则返回"SUCCESS"，否则返回失败信息。
        if (rows > 0) {
            return "SUCCESS";
        } else {
            return "update user failure.";
        }
    }

    public String deleteT(int id) {
        int rows = this.timeMapper.deleteT(id);
        // 2-2.判断删除用户是否成功。如果删除用户成功，则返回"SUCCESS"，
        // 否则返回失败信息。
        if (rows > 0) {
            return "SUCCESS";
        } else {
            return "delete user failure.";
        }
    }
}
